﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Xml;
using System.Linq.Expressions;

namespace ORMAC
{
    /// <summary>
    /// Interface to load a class hierarchy from xml data source, database or dataset
    /// </summary>
    public interface IReader
    {
        /// <summary>
        /// Sets the connection string for the ORMAC object
        /// </summary>
        /// <param name="connectionString"></param>
        void SetConnectionString(string connectionString = null);
        /// <summary>
        /// Loads a list of objects from database
        /// </summary>
        /// <typeparam name="T">Type of the object to be loaded</typeparam>
        /// <param name="connectionString">Connection string(Optional)</param>
        /// <param name="preFetch"></param>
        /// <param name="schemalName">Database schema name</param>
        /// <returns></returns>
        List<T> LoadFromDatabase<T>() where T : new();
        List<T> LoadFromDataSet<T>(DataSet dataSet) where T : new();
        List<T> LoadFromXml<T>(string xmlPathName, string schemalName = null) where T : new();
        List<T> LoadFromXmlDocument<T>(XmlDocument doc, string schemalName = null) where T : new();
        /// <summary>
        /// Selects a list of objects of <typeparamref name="T"/> from from database
        /// </summary>
        /// <typeparam name="T">Type of the object</typeparam>
        /// <param name="selectFunc">selection Lambda expression</param>
        /// <returns>List of objects selected from the database</returns>
        List<T> LoadFromDatabase<T>(Expression<Func<T, bool>> query) where T : new();
        List<T> LoadFromDatabase<T>(string query) where T : new();
        /// <summary>
        /// Executes a stored procedure
        /// </summary>
        /// <typeparam name="T">type of the return value from SP</typeparam>
        /// <param name="repository">the caller(repository) object</param>
        /// <param name="methodName">ths container method of the store procedure</param>
        /// <param name="paramList">list of stored procedure objects</param>
        /// <returns>object of <paramref name="T" type/></returns>
        List<T> Exceute<T>(object repository,string methodName,params object[] paramList) where T : new();
        T ExceuteScalar<T>(object repository, string methodName, params object[] paramList) ;
        /// <summary>
        /// sets the members of the object that should be preloaded from database
        /// use null if you only want scalar values to be loaded
        /// </summary>
        /// <typeparam name="T">type of the object to be loaded</typeparam>
        /// <param name="member">object member</param>
        /// <returns>ORMAC database reader</returns>
        IReader LoadObject<T>(Expression<Func<T,object>> member);
    }
}
